﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Collections;
namespace StockSBIE
{
    public class SQLiteAgent
    {
          protected static  SQLiteAgent sqlAgent;
         SQLiteConnection sqliteConnection= null;
        
        public static SQLiteAgent getInstance()
        {
            
            if(sqlAgent==null)
                sqlAgent= new SQLiteAgent();
            return sqlAgent;
        }
        public static SQLiteTransaction BeginTransation()
        {
            return getInstance().sqliteConnection.BeginTransaction();
        }
        protected SQLiteAgent()
        {
            String connString = @"data source=D:\sqlite\StockSBDetails\SBData.db;pooling=True;Read Only=False";
            sqliteConnection= new SQLiteConnection(connString);
            
            sqliteConnection.Open();
        }
        protected SQLiteCommand getCommand_internal()
        {
            SQLiteCommand cmd = new SQLiteCommand();
            cmd.CommandText = "";
            cmd.Connection =  getInstance().sqliteConnection;
            return cmd;
        }

        public static  SQLiteParameter createParam(Object v)
        {
            SQLiteParameter p = new SQLiteParameter();
            p.Value = v;
            return p;
        }

        public static  SQLiteCommand getCommand()
        {
            return getInstance().getCommand_internal();
        }
        public static void executeInsert(String sql, ArrayList ps)
        {

            SQLiteCommand cmd = getCommand();
            cmd.CommandText = sql;
            foreach (Object v in ps)
            {
                cmd.Parameters.Add(createParam(v));
            }
            cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            cmd.Dispose();
        }

        ~SQLiteAgent()
        {
            
        }
    }
}
